package main

import (
	"fmt"
	"unsafe"
)

type Args struct {
	num1 int32
	demo01
	num2 int32
}

type Flag struct {
	num1 int64
	num2 int64
}

type demo01 struct{}

type demo02 struct {
	//i int32
	a bool
	b struct{}
	e bool
	f int16
	i int32

	p string
	//l struct{}
}

type User struct {
	A int32    // 4	4
	B []int32  // 4	4
	C string   // 16	8
	D bool     // 1	1
	E struct{} // 0	1
}

type User2 struct {
	D bool     // 1	1
	E struct{} // 0	1
	A int32    // 4	4
	C string   // 16	8
	B []int32  // 24	8
}

func main() {
	fmt.Println(unsafe.Sizeof(Args{}))
	fmt.Println(unsafe.Sizeof(Flag{}))

	fmt.Printf("bool size:%d align: %d\n", unsafe.Sizeof(bool(true)), unsafe.Alignof(bool(true)))
	fmt.Printf("byte size:%d align: %d\n", unsafe.Sizeof(byte(0)), unsafe.Alignof(byte(0)))
	fmt.Printf("int8 size:%d align: %d\n", unsafe.Sizeof(int8(0)), unsafe.Alignof(int8(0)))
	fmt.Printf("int16 size:%d align: %d\n", unsafe.Sizeof(int16(0)), unsafe.Alignof(int16(0)))
	fmt.Printf("int32 size:%d align: %d\n", unsafe.Sizeof(int32(0)), unsafe.Alignof(int32(0)))
	fmt.Printf("int64 size:%d align: %d\n", unsafe.Sizeof(int64(0)), unsafe.Alignof(int64(0)))
	fmt.Printf("string size:%d align: %d\n", unsafe.Sizeof(""), unsafe.Alignof(""))

	fmt.Println("城中城")

	demo := demo01{}
	fmt.Printf("struct size:%d align: %d\n", unsafe.Sizeof(demo), unsafe.Alignof(demo))
	demo2 := Args{}
	fmt.Printf("struct size:%d align: %d\n", unsafe.Sizeof(demo2.demo01), unsafe.Alignof(demo2.demo01))
	demo3 := demo02{}
	fmt.Printf("struct size:%d align: %d\n", unsafe.Sizeof(demo3), unsafe.Alignof(demo3))

	demo4 := User{}
	fmt.Printf("A size:%d align: %d\n", unsafe.Sizeof(demo4.A), unsafe.Alignof(demo4.A))
	fmt.Printf("B size:%d align: %d\n", unsafe.Sizeof(demo4.B), unsafe.Alignof(demo4.B))
	fmt.Printf("C size:%d align: %d\n", unsafe.Sizeof(demo4.C), unsafe.Alignof(demo4.C))
	fmt.Printf("D size:%d align: %d\n", unsafe.Sizeof(demo4.D), unsafe.Alignof(demo4.D))
	fmt.Printf("E size:%d align: %d\n", unsafe.Sizeof(demo4.E), unsafe.Alignof(demo4.E))
	fmt.Printf("struct size:%d align: %d\n", unsafe.Sizeof(demo4), unsafe.Alignof(demo4))

	fmt.Printf("struct size:%d align: %d\n", unsafe.Sizeof(User2{}), unsafe.Alignof(User2{}))
}
